﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Devices;
using Devices.IDEXX;
namespace DevicesWPF.UCDevices
{
    /// <summary>
    /// UCIDEXX_VetLab_Station.xaml 的交互逻辑
    /// </summary>
    public partial class UCIDEXX_VetLab_Station : UserControl,DevicesWPF.IUCConfig
    {
        IDEXX_VetLab_Station idexxInfo;
        public UCIDEXX_VetLab_Station()
        {
            InitializeComponent();
        }
        public UCIDEXX_VetLab_Station(IDEXX_VetLab_Station idexx)
        {
            InitializeComponent();
            idexxInfo = idexx;
        }

        /// <summary>
        /// 读取配置
        /// </summary>
        /// <param name="hasErrors"></param>
        /// <returns></returns>
        public  Config GetConfig(out int hasErrors)
        {
            hasErrors = 1;
            if (idexxInfo.Config == null)
                idexxInfo.Config = new IDEXX_VetLab_StationConfig();
            IDEXX_VetLab_StationConfig config = (IDEXX_VetLab_StationConfig)idexxInfo.Config;

            config.CurrentConnectType = this.radioButtonServer.IsChecked==true ? ConnectType.TCP : ConnectType.FILE;
            config.StringIP = textBoxServerIp.Text;
            config.PDFPath = textBoxPDF.Text;
            config.RequestPath = textBoxRequest.Text;
            config.ResultPath = textBoxResult.Text;
            config.DateFormat = "MM/dd/yyyy HH:mm:ss";
            return idexxInfo.Config;
        }

        private void NewUCNX500IVCConfig_Load(object sender, RoutedEventArgs e)
        {
            if (this.idexxInfo != null)
            {
                IDEXX_VetLab_StationConfig config = (IDEXX_VetLab_StationConfig)idexxInfo.Config;
                if (config.CurrentConnectType == ConnectType.TCP)
                    this.radioButtonServer.IsChecked = true;
                else
                    this.radioButtonLocal.IsChecked = true;
                textBoxServerIp.Text = config.StringIP;
                textBoxPDF.Text = config.PDFPath;
                textBoxRequest.Text = config.RequestPath;
                textBoxResult.Text = config.ResultPath;
            }
        }


        private void radioButtonServer_CheckedChanged(object sender, RoutedEventArgs e)
        {
            this.groupBox2.Visibility = Visibility.Visible;
            this.groupBox1.Visibility = Visibility.Hidden;
        }

        private void RadioButtonLocal_Checked(object sender, RoutedEventArgs e)
        {
            this.groupBox2.Visibility = Visibility.Hidden;
            this.groupBox1.Visibility = Visibility.Visible;
        }
    }
}
